home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kopete / kopetecontact.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-09-10  |  17.2 KB  |  558 lines

  1. /*
  2.     kopetecontact.h - Kopete Contact
  3.  
  4.     Copyright (c) 2002-2004 by Duncan Mac-Vicar Prett <duncan@kde.org>
  5.     Copyright (c) 2002-2003 by Martijn Klingens       <klingens@kde.org>
  6.     Copyright (c) 2002-2004 by Olivier Goffart        <ogoffart @ tiscalinet.be>
  7.  
  8.     Kopete    (c) 2002-2004 by the Kopete developers  <kopete-devel@kde.org>
  9.  
  10.     *************************************************************************
  11.     *                                                                       *
  12.     * This library is free software; you can redistribute it and/or         *
  13.     * modify it under the terms of the GNU Lesser General Public            *
  14.     * License as published by the Free Software Foundation; either          *
  15.     * version 2 of the License, or (at your option) any later version.      *
  16.     *                                                                       *
  17.     *************************************************************************
  18. */
  19.  
  20. #ifndef __KOPETECONTACT_H__
  21. #define __KOPETECONTACT_H__
  22.  
  23. #include <qobject.h>
  24. #include <kurl.h>
  25. #include <kdemacros.h>
  26. #include "kopeteglobal.h"
  27.  
  28. #include "kopete_export.h"
  29.  
  30. class QImage;
  31. class KPopupMenu;
  32. class KAction;
  33.  
  34. namespace Kopete
  35. {
  36.  
  37. class Group;
  38. class MetaContact;
  39. class ChatSession;
  40. class OnlineStatus;
  41. class Plugin;
  42. class Protocol;
  43. class Account;
  44. typedef QPtrList<Group> GroupList;
  45.  
  46. /**
  47.  * @author Duncan Mac-Vicar P. <duncan@kde.org>
  48.  * @author Martijn Klingens <klingens@kde.org>
  49.  * @author Olivier Goffart <ogoffart@ tiscalinet.be>
  50.  *
  51.  * This class abstracts a generic contact
  52.  * Use it for inserting contacts in the contact list for example.
  53.  */
  54. class KOPETE_EXPORT Contact : public QObject
  55. {
  56.     Q_OBJECT
  57.  
  58.     Q_ENUMS( CanCreateFlags )
  59.     Q_PROPERTY( QString formattedName READ formattedName )
  60.     Q_PROPERTY( QString formattedIdleTime READ formattedIdleTime )
  61.     Q_PROPERTY( bool isOnline READ isOnline )
  62.     Q_PROPERTY( bool fileCapable READ isFileCapable WRITE setFileCapable )
  63.     Q_PROPERTY( bool canAcceptFiles READ canAcceptFiles )
  64.     //Q_PROPERTY( bool isReachable READ isReachable )
  65.     Q_PROPERTY( QString contactId READ contactId )
  66.     Q_PROPERTY( QString icon READ icon WRITE setIcon )
  67.     Q_PROPERTY( QString toolTip READ toolTip )
  68.     Q_PROPERTY( QString nickName READ nickName WRITE setNickName )
  69.     //Q_PROPERTY( unsigned long idleTime READ idleTime WRITE setIdleTime )
  70.  
  71. public:
  72.     /**
  73.      * \brief Create new contact.
  74.      *
  75.      * <b>The parent MetaContact must not be NULL</b>
  76.      *
  77.      * \note id is required to be unique per protocol and per account.
  78.      * Across those boundaries ids may occur multiple times.
  79.      * The id is solely for comparing items safely (using pointers is
  80.      * more crash-prone). DO NOT assume anything regarding the id's
  81.      * value! Even if it may look like an ICQ UIN or an MSN passport,
  82.      * this is undefined and may change at any time!
  83.      *
  84.      * @param account is the parent account. this constructor automatically register the contact to the account
  85.      * @param id is the Contact's unique Id (mostly the user's login)
  86.      * @param parent is the parent @ref MetaContact this Contact is part of
  87.      * @param icon is an optional icon
  88.      */
  89.     Contact( Account *account, const QString &id, MetaContact *parent,
  90.         const QString &icon = QString::null );
  91.  
  92.     ~Contact();
  93.  
  94.     /**
  95.      * \brief Get the metacontact for this contact
  96.      * @return The MetaContact object for this contact
  97.      */
  98.     MetaContact *metaContact() const;
  99.  
  100.  
  101.     /**
  102.      * \brief Get the unique id that identifies a contact.
  103.      *
  104.      * \note Id is required to be unique per protocol and per account.
  105.      * Across those boundaries ids may occur multiple times.
  106.      * The id is solely for comparing items safely (using pointers is
  107.      * more crash-prone). DO NOT assume anything regarding the id's
  108.      * value! Even if it may look like an ICQ UIN or an MSN passport,
  109.      * this is undefined and may change at any time!
  110.      *
  111.      * @return The unique id of the contact
  112.      */
  113.     QString contactId() const;
  114.  
  115.     /**
  116.      * \brief Get the protocol that the contact belongs to.
  117.      *
  118.      * simply return account()->protocol()
  119.      *
  120.      * @return the contact's protocol
  121.      */
  122.     Protocol* protocol() const;
  123.  
  124.     /**
  125.      * \brief Get the account that this contact belongs to
  126.      *
  127.      * @return the Account object for this contact
  128.      */
  129.     Account* account() const;
  130.  
  131.     /**
  132.      * \brief Move this contact to a new MetaContact.
  133.      * This basically reparents the contact and updates the internal
  134.      * data structures.
  135.      * If the old contact is going to be empty, a question may ask to the user if it wants to delete the old contact.
  136.      *
  137.      * @param m The new MetaContact to move this contact to
  138.      */
  139.     void setMetaContact(MetaContact *m);
  140.  
  141.  
  142.     /**
  143.      * @brief Get whether this contact is online.
  144.      * @return @c true if the contact is online, @c false otherwise.
  145.      */
  146.     bool isOnline() const;
  147.  
  148.     /**
  149.      * \brief Get whether this contact can receive messages
  150.      *
  151.      * Used in determining if the contact is able to
  152.      * receive messages.  This function must be defined by child classes
  153.      *
  154.      * @return true if the contact can be reached
  155.      * @return false if the contact can not be reached
  156.      */
  157.     // FIXME: After KDE 3.2 we should split this into a public, NON-virtual
  158.     //        isReachable() accessor that checks for account->isConnected()
  159.     //        and then calls a new virtual method that does the
  160.     //        protocol-specific work, like 'doIsUnreachable' or so - Martijn
  161.     //
  162.     //FIXME: Can this be made const please? - JK
  163.     virtual bool isReachable();
  164.  
  165.     /**
  166.      * @brief Serialize the contact for storage in the contact list.
  167.      *
  168.      * The provided serializedData contain the contact id in the field
  169.      * "contactId". If you don't like this, or don't want to
  170.      * store these fields at all,
  171.      * you are free to remove them from the list.
  172.      *
  173.      * Most plugins don't need more than these fields, so they only need
  174.      * to set the address book fields themselves. If you have nothing to
  175.      * save at all you can clear the QMap, an empty map is treated as
  176.      * 'nothing to save'.
  177.      *
  178.      * The provided addressBookFields QMap contains the index field as
  179.      * marked with @ref Plugin::addAddressBookField() with the
  180.      * contact id as value. If no index field is available the QMap is
  181.      * simply passed as an empty map.
  182.      *
  183.      * @sa Protocol::deserializeContact
  184.      */
  185.     virtual void serialize( QMap<QString, QString> &serializedData, QMap<QString, QString> &addressBookData );
  186.  
  187.     /**
  188.      * @brief Serialize the contacts persistent properties for storage in the contact list.
  189.      *
  190.      * Does the same as @ref serialize() does but for KopeteContactProperties
  191.      * set in this contact with their persistency flag turned on.
  192.      * In contrary to @ref serialize() this does not need to be reimplemented.
  193.      *
  194.      */
  195.     void serializeProperties(QMap<QString, QString> &serializedData);
  196.  
  197.     /**
  198.      * @brief Deserialize the contacts persistent properties
  199.      */
  200.     void deserializeProperties(QMap<QString, QString> &serializedData);
  201.  
  202.     /**
  203.      * @brief Get the online status of the contact
  204.      * @return the online status of the contact
  205.      */
  206.     OnlineStatus onlineStatus() const;
  207.  
  208.     /**
  209.      * \brief Set the contact's online status
  210.      */
  211.     void setOnlineStatus(const OnlineStatus &status);
  212.  
  213.     /**
  214.      * \brief Get the set of custom menu items for this contact
  215.      *
  216.      * Returns a set of custom menu items for the context menu
  217.      * which is displayed in showContextMenu (private).  Protocols
  218.      * should use this to add protocol-specific actions to the
  219.      * popup menu. Kopete take care of the deletion of the action collection.
  220.      * Actions should have the collection as parent.
  221.      *
  222.      * @return Collection of menu items to be show on the context menu
  223.      * @todo if possible, try to use KXMLGUI
  224.      */
  225.     virtual QPtrList<KAction> *customContextMenuActions();
  226.  
  227.     /**
  228.      * @todo  What is this function for ?
  229.      */
  230.     virtual QPtrList<KAction> *customContextMenuActions( ChatSession *manager );
  231.  
  232.     /**
  233.      * @brief Get the Context Menu for this contact
  234.      *
  235.      * This menu includes generic actions common to each protocol, and action defined in
  236.      * @ref customContextMenuActions()
  237.      */
  238.     KPopupMenu *popupMenu( ChatSession *manager = 0L );
  239.  
  240.     /**
  241.      * \brief Get whether or not this contact is capable of file transfers
  242.      *
  243.      *
  244.      * \see setFileCapable()
  245.      * \return true if the protocol for this contact is capable of file transfers
  246.      * \return false if the protocol for this contact is not capable of file transfers
  247.      *
  248.      * @todo have a capabilioties. or move to protocol capabilities
  249.      */
  250.     bool isFileCapable() const;
  251.  
  252.     /**
  253.      * \brief Set the file transfer capability of this contact
  254.      *
  255.      * \param filecap The new file transfer capability setting
  256.      * @todo have a capabilioties. or move to protocol capabilities
  257.      */
  258.     void setFileCapable( bool filecap );
  259.  
  260.     /**
  261.      * \brief Get whether or not this contact can accept file transfers
  262.      *
  263.      * This function checks to make sure that the contact is online as well as
  264.      * capable of sending files.
  265.      * \see isReachable()
  266.      * @return true if this contact is online and is capable of receiving files
  267.      * @todo have a capabilioties. or move to protocol capabilities
  268.      */
  269.     bool canAcceptFiles() const;
  270.  
  271.     enum CanCreateFlags {  CannotCreate=false , CanCreate=true  };
  272.  
  273.     /**
  274.      * Returns the primary message manager affiliated with this contact
  275.      * Although a contact can have more than one active message manager
  276.      * (as is the case with MSN at least), only one message manager will
  277.      * ever be the contacts "primary" message manager.. aka the 1 on 1 chat.
  278.      * This function should always return that instance.
  279.      *
  280.      * @param canCreate If a new message manager can be created in addition
  281.      * to any existing managers. Currently, this is only set to true when
  282.      * a chat is initiated by the user by clicking the contact list.
  283.      */
  284.     virtual ChatSession * manager( CanCreateFlags canCreate = CannotCreate ) =0;
  285.  
  286.     /**
  287.      * Returns the name of the icon to use for this contact
  288.      *  If null, the protocol icon need to be used.
  289.      * The icon is not colored, nor has the status icon overloaded
  290.      */
  291.     QString& icon() const;
  292.  
  293.     /**
  294.      * @brief Change the icon to use for this contact
  295.      * If you don't want to have the protocol icon as icon for this contact, you may set
  296.      * another icon.  The icon doesn't need to be colored with the account icon as this operation
  297.      * will be performed later.
  298.      *
  299.      * if you want to go back to the protocol icon, set a null string.
  300.      */
  301.     void setIcon( const QString& icon );
  302.  
  303.     /**
  304.      * \brief Get the time (in seconds) this contact has been idle
  305.      * It will return the time set in @ref setIdleTime() with an addition of the time
  306.      * since you set this last time
  307.      * @return time this contact has been idle for, in seconds
  308.      //
  309.          // FIXME: Can we make this just 'unsigned long' ? QT Properties can't handle
  310.          // 'unsigned long int'
  311.      */
  312.     virtual unsigned long int idleTime() const;
  313.  
  314.     /**
  315.      * \brief Set the current idle time in seconds.
  316.      * Kopete will automatically calculate the time in @ref idleTime
  317.      * except if you set 0.
  318.      //
  319.      // FIXME: Can we make this just 'unsigned long' ? QT Properties can't handle
  320.      // 'unsigned long int'
  321.      */
  322.     void setIdleTime(unsigned long int);
  323.  
  324.     /**
  325.      * @return A QStringList containing all property keys
  326.      **/
  327.     QStringList properties() const;
  328.  
  329.     /**
  330.      * Check for existance of a certain property stored
  331.      * using "key".
  332.      * \param key the property to check for
  333.      **/
  334.     bool hasProperty(const QString &key) const;
  335.  
  336.     /**
  337.      * \brief Get the value of a property with key "key".
  338.      *
  339.      * If you don't know the type of the returned QVariant, you will need
  340.      * to check for it.
  341.      * \return the value of the property
  342.      **/
  343.     const Kopete::ContactProperty &property(const QString &key) const;
  344.     const Kopete::ContactProperty &property(const Kopete::ContactPropertyTmpl &tmpl) const;
  345.  
  346.     /**
  347.      * \brief Add or Set a property for this contact.
  348.      *
  349.      * @param tmpl The template this property is based on, key, label etc. are
  350.      * taken from this one
  351.      * @param value The value to store
  352.      *
  353.      * \note Setting a NULL value or an empty QString castable value
  354.      * removes the property if it already existed.
  355.      * <b>Don't</b> abuse this for property-removal, instead use
  356.      * @ref removeProperty() if you want to remove on purpose.
  357.      * The Removal is done to clean up the list of properties and to purge them
  358.      * from UI.
  359.      **/
  360.     void setProperty(const Kopete::ContactPropertyTmpl &tmpl, const QVariant &value);
  361.  
  362.         /**
  363.      * \brief Convenience method to set the nickName property to the specified value
  364.      * @param name The nickname to set
  365.      */
  366.     void setNickName( const QString &name );
  367.  
  368.     /**
  369.      * \brief Convenience method to retrieve the nickName property.
  370.      *
  371.      * This method will return the contactId if there has been no nickName property set
  372.      */
  373.     QString nickName() const;
  374.  
  375.     /**
  376.      * \brief Remove a property if it exists
  377.      *
  378.      * @param tmpl the template this property is based on
  379.      **/
  380.     void removeProperty(const Kopete::ContactPropertyTmpl &tmpl);
  381.  
  382.     /**
  383.      * \brief Get the tooltip for this contact
  384.      * Makes use of formattedName() and formattedIdleTime().
  385.      * \return an RTF tooltip depending on KopetePrefs settings
  386.      **/
  387.     QString toolTip() const;
  388.  
  389.     /**
  390.      * Returns a formatted string of "firstName" and/or "lastName" properties
  391.      * if present.
  392.      * Suitable for GUI display
  393.      **/
  394.     QString formattedName() const;
  395.  
  396.     /**
  397.      * Returns a formatted string of idleTime().
  398.      * Suitable for GUI display
  399.      **/
  400.     QString formattedIdleTime() const;
  401.  
  402.     /**
  403.      * used in @ref sync()
  404.      */
  405.     enum Changed{ MovedBetweenGroup = 0x01, ///< the contact has been moved between groups
  406.               DisplayNameChanged = 0x02 ///< the displayname of the contact changed
  407.     };
  408.  
  409.  
  410. public slots:
  411.     /**
  412.      * This should typically pop up a KopeteChatWindow
  413.      */
  414.     void startChat();
  415.  
  416.     /**
  417.      * Pops up an email type window
  418.      */
  419.     void sendMessage();
  420.  
  421.     /**
  422.      * The user clicked on the contact, do the default action
  423.      */
  424.     void execute();
  425.  
  426.     /**
  427.      * Changes the MetaContact that this contact is a part of.  This function
  428.      * is called by the KAction changeMetaContact that is part of the context
  429.      * menu.
  430.      */
  431.     void changeMetaContact();
  432.  
  433.     /**
  434.      * Method to retrieve user information.  Should be implemented by
  435.      * the protocols, and popup some sort of dialog box
  436.      *
  437.      * reimplement it to show the informlation
  438.      * @todo rename and make it pure virtual
  439.      */
  440.     virtual void slotUserInfo() {};
  441.  
  442.     /**
  443.      * @brief Syncronise the server and the metacontact.
  444.      * Protocols with server-side contact lists can implement this to
  445.      * sync the server groups with the metaContact groups. Or the server alias if any.
  446.      *
  447.      * This method is called every time the metacontact has been moved or renamed.
  448.      *
  449.      * default implementation does nothing
  450.      *
  451.      * @param changed is a bitmask of the @ref Changed enum which say why the call to this funtion is done.
  452.      */
  453.     virtual void sync(unsigned int changed = 0xFF);
  454.  
  455.     /**
  456.      * Method to delete a contact from the contact list,
  457.      * should be implemented by protocol plugin to handle
  458.      * protocol-specific actions required to delete a contact
  459.      * (ie. messages to the server, etc)
  460.      * the default implementation simply call deleteLater()
  461.      */
  462.     virtual void deleteContact();
  463.  
  464.     /**
  465.      * This is the Contact level slot for sending files. It should be
  466.      * implemented by all contacts which have the setFileCapable() flag set to
  467.      * true. If the function is called through the GUI, no parameters are sent
  468.      * and they take on default values (the file is chosen with a file open dialog)
  469.      *
  470.      * @param sourceURL The actual KURL of the file you are sending
  471.      * @param fileName (Optional) An alternate name for the file - what the
  472.      * receiver will see
  473.      * @param fileSize (Optional) Size of the file being sent. Used when sending
  474.      * a nondeterminate
  475.      *                file size (such as over  asocket
  476.      */
  477.     virtual void sendFile( const KURL &sourceURL = KURL(),
  478.                    const QString &fileName = QString::null, uint fileSize = 0L );
  479.  
  480. private slots:
  481.  
  482.     /**
  483.      * This add the contact totally in the list if it was a temporary contact
  484.      */
  485.     void slotAddContact();
  486.  
  487.     /**
  488.      * slot called when the action "delete" is called.
  489.      */
  490.     void slotDelete();
  491.  
  492.     /**
  493.      * slot called when the action "block" is called.
  494.      */
  495.     void slotBlock();
  496.  
  497.     /**
  498.      * slot called when the action "unblock" is called.
  499.      */
  500.     void slotUnblock();
  501.  
  502.     /**
  503.      * The account's isConnected has changed.
  504.      */
  505.     void slotAccountIsConnectedChanged();
  506.  
  507. signals:
  508.     /**
  509.      * The contact's online status changed
  510.      */
  511.     void onlineStatusChanged( Kopete::Contact *contact,
  512.         const Kopete::OnlineStatus &status, const Kopete::OnlineStatus &oldStatus );
  513.  
  514.     /**
  515.      * The contact is about to be destroyed.
  516.      * Called when entering the destructor. Useful for cleanup, since
  517.      * metaContact() is still accessible at this point.
  518.      *
  519.      * @warning this signal is emit in the Contact destructor, so all
  520.      * virtual method are not available
  521.      */
  522.     void contactDestroyed( Kopete::Contact *contact );
  523.  
  524.     /**
  525.      * The contact's idle state changed.
  526.      * You need to emit this signal to update the view.
  527.      * That mean when activity has been noticed
  528.      */
  529.     void idleStateChanged( Kopete::Contact *contact );
  530.  
  531.     /**
  532.      * One of the contact's properties has changed.
  533.      * @param contact this contact, useful for listening to signals from more than one contact
  534.      * @param key the key whose value has changed
  535.      * @param oldValue the value before the change, or an invalid QVariant if the property is new
  536.      * @param newValue the value after the change, or an invalid QVariant if the property was removed
  537.      */
  538.     void propertyChanged( Kopete::Contact *contact, const QString &key,
  539.         const QVariant &oldValue, const QVariant &newValue );
  540.  
  541. protected:
  542.     virtual void virtual_hook(uint id, void *data);
  543.  
  544. private:
  545.     class Private;
  546.     Private *d;
  547.  
  548.  
  549. };
  550.  
  551.  
  552. } //END namespace Kopete
  553.  
  554. #endif
  555.  
  556. // vim: set noet ts=4 sts=4 sw=4:
  557.  
  558.